#include "xcommandtransaction.h"
#include <stdio.h>
#include <string.h>
#include "xcommand.h"
#include "libxsip.h"
#include <assert.h>
#include "xsip.h"

XSIPCommandTransaction::XSIPCommandTransaction()
	: XSIPTransaction(XSIPTransaction::TRANSACTION_TYPE_CMD)
{
}

XSIPCommandTransaction::~XSIPCommandTransaction()
{

}

void* XSIPCommandTransaction::getObject(const char* name) const
{
	if (strcmp(name, "XSIPCommandTransaction") == 0)
		return const_cast<XSIPCommandTransaction*>(this);
	else
		return XSIPTransaction::getObject(name);
}

void XSIPCommandTransaction::onEvent(XSIPTransaction* transaction, int eventCode)
{
	if (getState() != XSIPTransaction::TSX_STATE_DESTORY)
	{
		setState(XSIPTransaction::TSX_STATE_DESTORY);
		XSIPCall* command = (XSIPCall*) m_owner->getObject("XSIPCall");
		command->onEvent(transaction, eventCode);
		DeleteCall* del = new DeleteCall(command);
		XSIPEngine::getCurrentThreadEngine()->addEntry(del);
	}
}
